﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace DAO
{
    public class DataProvider
    {
        static string strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=qlns.accdb;Jet OLEDB:Database Password=123;";
        static OleDbConnection connection;
        static bool isOpenConnection=false;
        public static void OpenConnection()
        {
            if (isOpenConnection==false)
            {
                connection=new OleDbConnection(strConnectionString);
                isOpenConnection =true;
            }
           
            connection.Open();
        }

        public static void CloseConnection()
        {
            connection.Close();
        }

        public static void ExecNonQuery(string strSQl)
        {
            OpenConnection();
            OleDbCommand command = new OleDbCommand(strSQl,connection);
            command.ExecuteNonQuery();
            CloseConnection();
        }

        public static DataTable ExecQuery(string strSQl)
        {
            DataTable dt = new DataTable();
            OleDbDataAdapter adapter = new OleDbDataAdapter(strSQl,strConnectionString);
            adapter.Fill(dt);
            return dt;
          
        }
    }
}
